//
//  OAShowDocViewController.m
//  LongOA
//
//  Created by XuJiuming on 15/10/7.
//  Copyright (c) 2015年 梁文朗. All rights reserved.
//

#import "OAShowDocViewController.h"
#import "GetOADocHTMLRequest.h"
#import "GetOADocHTMLResponse.h"
#import "OAFlowToNextRequest.h"
#import "OAFlowToNextResponse.h"
#import "OAFlowOpposeRequest.h"
#import "OAFlowOpposeResponse.h"
#import "OADocDisagreeBackRequest.h"
#import "OADocDisagreeBackResponse.h"
#import "OADocUrgeRequest.h"
#import "OADocUrgeResponse.h"
#import "MessagePhotoViewDocShow.h"
#import "OASelectFileViewController.h"
#import "OADocInitRequest.h"
#import "OADocInitResponse.h"

@interface OAShowDocViewController ()<UITableViewDataSource,UITableViewDelegate,MessagePhotoViewDelegateDocShow,UIWebViewDelegate>
{
    UIScrollView* scrollView;
    UIView* topView;
    UIView *_maskV;
    UIView *_menuV;
    UITableView* _tableView;
    NSArray* arrSteps;
    NSArray* arrAnnex;
}
@property(nonatomic)int idocid;
@property (nonatomic,strong) MessagePhotoViewDocShow *photoView;
@end

@implementation OAShowDocViewController
@synthesize mydict,arrList;
@synthesize itype,iindex;

- (void)leftBarClicked:(id)sender {
    [self dismissViewControllerAnimated:NO completion:nil];
}

- (void)createBottomButton:(CGRect)rect withTitle:(NSString*)title withTag:(int)tag withImg:(NSString*)imgName withView:(UIView*)view{
    UIView* view5=[[UIView alloc]initWithFrame:rect];
    view5.backgroundColor=[UIColor clearColor];
    [self.view addSubview:view5];
    
    UIImageView* img1=[[UIImageView alloc] initWithFrame:CGRectMake((view5.width-20.0)/2,5.0, 20.0, 20.0)];
    img1.image=[UIImage imageNamed:imgName];
    [view5 addSubview:img1];
    
    UILabel *labb1=[[UILabel alloc]initWithFrame:CGRectMake(0.0, img1.bottom, view5.width, 15.0)];
    labb1.backgroundColor=[UIColor clearColor];
    labb1.text=title;
    labb1.textAlignment=NSTextAlignmentCenter;
    labb1.font=[UIFont systemFontOfSize:10.0];
    labb1.textColor=RGBColor(40, 119, 193, 1);
    [view5 addSubview:labb1];
    
    UIButton *bottom1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0.0, view5.width, view5.height)];
    [bottom1 addTarget:self action:@selector(bottomItemPressed:) forControlEvents:UIControlEventTouchUpInside];
    [bottom1 setBackgroundColor:[UIColor clearColor]];
    bottom1.tag=tag;
    [view5 addSubview:bottom1];
    
    [view addSubview:view5];
}

-(void)bottomItemPressed:(id)sender {
    UIButton* btn=(UIButton*)sender;
    switch (btn.tag) {
            #pragma mark 上一条
        case 1001:
        {

            if (iindex>0) {
                iindex--;
            } else {
                return;
            }
            mydict=[arrList objectAtIndex:iindex];
            _idocid=[[mydict objectForKey:@"docid"] intValue];
            [self createTopView];
        }
            break;
            #pragma mark 下一条
        case 1002:
        {
            if (iindex<[arrList count]-1) {
                iindex++;
            } else {
                return;
            }
            mydict=[arrList objectAtIndex:iindex];
            _idocid=[[mydict objectForKey:@"docid"] intValue];
            [self createTopView];
        }
            break;
#pragma mark 同意
        case 1003:
        {
            if (_menuV) {
                [_menuV removeFromSuperview];
            }
            [self createMenu:@"请输入审核意见" withtag:7];
            [_maskV addSubview:_menuV];
            
            [self showMenuWithBool:TRUE complete:^()
             {
             }];
        }
            break;
#pragma mark 反对
        case 1004:
        {
            if (_menuV) {
                [_menuV removeFromSuperview];
            }
            [self createMenu:@"请输入反对原因" withtag:8];
            [_maskV addSubview:_menuV];
            
            [self showMenuWithBool:TRUE complete:^()
             {
             }];
        }
            break;
#pragma mark 上一步
        case 1005:
        {
            if (_menuV) {
                [_menuV removeFromSuperview];
            }
            [self createMenu:@"请输入否决上一步原因" withtag:9];
            [_maskV addSubview:_menuV];
            
            [self showMenuWithBool:TRUE complete:^()
             {
             }];

        }
            break;
            #pragma mark 催办
        case 1006:
        {
            if (_menuV) {
                [_menuV removeFromSuperview];
            }
            [self createMenu:@"请输入催办留言" withtag:10];
            [_maskV addSubview:_menuV];
            
            [self showMenuWithBool:TRUE complete:^()
             {
             }];

        }
            break;
        default:
            break;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor colorWithRed:235.0/255.0 green:230.0/255.0 blue:235.0/255.0 alpha:1.0];
    NSString* strTitle=@"公文查看";
    int itag=[[mydict objectForKey:@"docflag"] intValue];
    switch (itag) {
        case 0:
            strTitle=[NSString stringWithFormat:@"%@[%@]",strTitle,@"草稿"];
            break;
        case 1:
            strTitle=[NSString stringWithFormat:@"%@[%@]",strTitle,@"处理中"];
            break;
        case 2:
            strTitle=[NSString stringWithFormat:@"%@[%@]",strTitle,@"被否决"];
            break;
        case 11:
            strTitle=[NSString stringWithFormat:@"%@[%@]",strTitle,@"完成"];
            break;
        case 12:
            strTitle=[NSString stringWithFormat:@"%@[%@]",strTitle,@"作废"];
            break;
        default:
            break;
    }
    [self createNavWithTitle:strTitle createMenuItem:^UIView *(int nIndex)
     {
         float btnwidth=40.0f;
         float btnheight=40.0f;
         if (nIndex ==0)
         {
             UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
             [btn setFrame:CGRectMake(10.0f, 20.0f+(self.navView.height-20 - 40)/2, btnwidth, btnheight)];
             [btn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
             [btn addTarget:self action:@selector(leftBarClicked:) forControlEvents:UIControlEventTouchUpInside];
             btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
             return btn;
         }
         if (itype==3) {
             if (nIndex ==2)
             {
                 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                 [btn setFrame:CGRectMake(self.navView.width - btnwidth, 20.0f+(self.navView.height-20 - 40)/2, btnwidth, btnheight)];
                 [btn setImage:[UIImage imageNamed:@"ic_send"] forState:UIControlStateNormal];
                 [btn addTarget:self action:@selector(rightBarClicked1:) forControlEvents:UIControlEventTouchUpInside];
                 
                 return btn;
             }
//             if (nIndex ==3)
//             {
//                 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//                 [btn setFrame:CGRectMake(self.navView.width - btnwidth*2, 20.0f+(self.navView.height-20 - 40)/2, btnwidth, btnheight)];
//                 [btn setImage:[UIImage imageNamed:@"ic_save"] forState:UIControlStateNormal];
//                 [btn addTarget:self action:@selector(rightBarClicked2:) forControlEvents:UIControlEventTouchUpInside];
//                 
//                 return btn;
//             }
         }
         

         return nil;
     }];
    
    UIView* view8=[[UIView alloc] initWithFrame:CGRectMake(-1.0, SCREEN_HEIGHT-44.0, SCREEN_WIDTH+2.0, 44.0)];
    view8.layer.borderColor=[UIColor darkTextColor].CGColor;
    view8.backgroundColor=[UIColor whiteColor];
    view8.layer.borderWidth=1.0f;
    [self.view addSubview:view8];
    
    float fwidth=SCREEN_WIDTH/6.0;
    NSArray* arrName=@[@"上一页",@"下一页",@"同意",@"反对",@"上一步",@"催办"];
    NSArray* arrPic=@[@"ic_up_normal",@"ic_down_normal",@"ic_pass_normal",@"ic_fail_normal",@"ic_disagree_back_normal",@"ic_urge_normal"];
    for (int i=0; i<[arrName count]; i++) {
        [self createBottomButton:CGRectMake(fwidth*i, 0.0, fwidth,view8.height) withTitle:[arrName objectAtIndex:i] withTag:1001+i withImg:[arrPic objectAtIndex:i] withView:view8];
    }
    
    scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0.0, self.navView.bottom, SCREEN_WIDTH, SCREEN_HEIGHT-self.navView.bottom-44)];
    [self.view addSubview:scrollView];
    [self createTopView];
    
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0.0, topView.bottom+10.0, SCREEN_WIDTH, 44.0) style:UITableViewStylePlain];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.backgroundColor=[UIColor clearColor];
    _tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    _tableView.delaysContentTouches=NO;
    _tableView.layer.borderColor=[UIColor whiteColor].CGColor;
    _tableView.layer.cornerRadius=5.0;
    [scrollView addSubview:_tableView];
    [self setExtraCellLineHidden:_tableView];
    
    [self getDocHtml];
    //阴影
    _maskV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [_maskV setClipsToBounds:YES];
    [self.view addSubview:_maskV];
    [_maskV setHidden:YES];
    UIView *bg = [[UIView alloc] initWithFrame:_maskV.bounds];
    [bg setBackgroundColor:[UIColor blackColor]];
    [bg setAlpha:0.5];
    [_maskV addSubview:bg];
    UITapGestureRecognizer *tSM =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showMenuByTap:)];
    [bg addGestureRecognizer:tSM];
    
    _idocid=[[mydict objectForKey:@"docid"] intValue];
}
- (void)rightBarClicked2:(id)sender {
    //保存
    //[self saveData:0 withid:0];
}
- (void)rightBarClicked1:(id)sender {
    //发送
    //[self saveData:2 withid:0];
    NSString* token=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    int setid=[[[NSUserDefaults standardUserDefaults] objectForKey:@"setid"] intValue];
    
    OADocInitRequest* request = [[OADocInitRequest alloc] init];
    request.token = token;
    request.docid=[[mydict objectForKey:@"docid"] intValue];
    id<ILJClient> clinet = [[OAIpdataBase shareInstance] getPool:setid];
    [clinet Doexecute:request
             RspClass:[OADocInitResponse class]
               andMsg:@"获取信息..."
              andView:self.view
globalTimelinePostsWithBlock:^(id rsp) {
    OADocInitResponse* rslt = rsp;
    
    if (rslt.ErrMsg) {
        NSLog(@"%@",rslt.ErrMsg);
    }
    else{
        [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshData" object:nil];
        [self dismissViewControllerAnimated:NO completion:nil];
    }
}];
}
-(void)setExtraCellLineHidden: (UITableView *)tableView {
    UIView *view =[ [UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
    [tableView setTableHeaderView:view];
}
#pragma mark 创建弹出视图
- (void)showMenuWithBool:(BOOL)bShow complete:(void(^)())complete
{
    if (bShow)
    {
        [_maskV setHidden:NO];
        
        [UIView animateWithDuration:0.3 animations:^
         {
             //float yy=SCREEN_HEIGHT-300.0;
             //_menuV.y=_maskV.height-300.0;
             //_menuV.frame=CGRectMake(0.0, SCREEN_HEIGHT-300.0, SCREEN_WIDTH, 300.0);
         } completion:^(BOOL finished)
         {
             complete();
         }];
    }else
    {
        [UIView animateWithDuration:0.3 animations:^
         {
             //_menuV.y=_maskV.height;
         } completion:^(BOOL finished)
         {
             [_maskV setHidden:YES];
             complete();
         }];
    }
}
- (void)showMenuByTap:(UITapGestureRecognizer *)tap
{
    [self showMenuWithBool:FALSE complete:^()
     {
     }];
    //    UIButton *btn = (UIButton *)self.rightV;
    //    [btn setUserInteractionEnabled:NO];
    //    [btn setSelected:!btn.selected];
    //    [self showMenuWithBool:btn.selected complete:^()
    //     {
    //         [btn setUserInteractionEnabled:YES];
    //     }];
}

- (void)createMenu:(NSString*)title withtag:(int)tag {
    _menuV=[[UIView alloc] initWithFrame:CGRectMake(30.0, (_maskV.height-130.0)/2, 260.0, 130.0)];
    _menuV.backgroundColor=[UIColor whiteColor];
    UILabel *lab1=[[UILabel alloc]initWithFrame:CGRectMake(15.0, 0.0, _menuV.width-30.0, 40.0)];
    lab1.backgroundColor=[UIColor clearColor];
    lab1.text=title;
    lab1.textAlignment=NSTextAlignmentLeft;
    lab1.font=[UIFont boldSystemFontOfSize:14.0];
    lab1.textColor=[UIColor darkTextColor];
    [_menuV addSubview:lab1];
    
    UITextField* txtInput=[[UITextField alloc] initWithFrame:CGRectMake(15.0, lab1.bottom, _menuV.width-30.0, 30.0)];
    txtInput.font=[UIFont systemFontOfSize:14.0];
    txtInput.textColor=[UIColor darkTextColor];
    txtInput.tag=777;
    [_menuV addSubview:txtInput];
    UIView* vi1=[[UIView alloc] initWithFrame:CGRectMake(15, txtInput.bottom, _menuV.width-30.0, 0.5)];
    vi1.backgroundColor=[UIColor lightGrayColor];
    [_menuV addSubview:vi1];
    

    
    UIButton* btn=[[UIButton alloc] initWithFrame:CGRectMake(_menuV.width-55.0*2-30.0, _menuV.height-44.0, 55.0, 33.0)];
    [btn setTitle:@"取消" forState:UIControlStateNormal];
    btn.titleLabel.font=[UIFont systemFontOfSize:15.0];
    [btn setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor clearColor]];
    [btn addTarget:self action:@selector(backToMain:) forControlEvents:UIControlEventTouchUpInside];
    [_menuV addSubview:btn];
    
    UIButton* btn1=[[UIButton alloc] initWithFrame:CGRectMake(btn.right+5.0, _menuV.height-44.0, 55.0, 33.0)];
    [btn1 setTitle:@"确定" forState:UIControlStateNormal];
    btn1.titleLabel.font=[UIFont systemFontOfSize:15.0];
    [btn1 setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
    btn1.tag=tag+1;
    [btn1 setBackgroundColor:[UIColor clearColor]];
    [btn1 addTarget:self action:@selector(backToMain1:) forControlEvents:UIControlEventTouchUpInside];
    [_menuV addSubview:btn1];
}
#pragma mark 确认
- (void)backToMain1:(id)sender {
    //data
    UITextField* txt=(UITextField*)[self.view viewWithTag:777];
    UIButton* btn=(UIButton*)sender;
    switch (btn.tag) {
        case 8:
        {
            //同意
            
        }
            break;
        case 9:
        {
            //反对
            if (txt.text.length==0) {
                [self showAlertWithContent:@"请输入反对原因"];
                return;
            }
            NSString* token=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
            int setid=[[[NSUserDefaults standardUserDefaults] objectForKey:@"setid"] intValue];
            
            OAFlowOpposeRequest* request = [[OAFlowOpposeRequest alloc] init];
            request.token = token;
            request.docID = [[mydict objectForKey:@"docid"] intValue];
            request.dscrp=txt.text;
            id<ILJClient> clinet = [[OAIpdataBase shareInstance] getPool:setid];
            [clinet Doexecute:request
                     RspClass:[OAFlowOpposeResponse class]
                       andMsg:@"获取信息..."
                      andView:self.view
 globalTimelinePostsWithBlock:^(id rsp) {
     OAFlowOpposeResponse* rslt = rsp;
     
     if (rslt.ErrMsg) {
         [self showAlertWithContent:rslt.ErrMsg];
         NSLog(@"%@",rslt.ErrMsg);
     }
     else{
         
     }
 }];
        }
            break;
        case 10:
        {
            //上一步
            if (txt.text.length==0) {
                [self showAlertWithContent:@"请输入否决上一步原因"];
                return;
            }
            NSString* token=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
            int setid=[[[NSUserDefaults standardUserDefaults] objectForKey:@"setid"] intValue];
            
            OADocDisagreeBackRequest* request = [[OADocDisagreeBackRequest alloc] init];
            request.token = token;
            request.docid = [[mydict objectForKey:@"docid"] intValue];
            request.DisagreeMsg=txt.text;
            id<ILJClient> clinet = [[OAIpdataBase shareInstance] getPool:setid];
            [clinet Doexecute:request
                     RspClass:[OADocDisagreeBackResponse class]
                       andMsg:@"获取信息..."
                      andView:self.view
 globalTimelinePostsWithBlock:^(id rsp) {
     OADocDisagreeBackResponse* rslt = rsp;
     
     if (rslt.ErrMsg) {
         [self showAlertWithContent:rslt.ErrMsg];
         NSLog(@"%@",rslt.ErrMsg);
     }
     else{
         
     }
 }];
        }
            break;
        case 11:
        {
            //催办
            
            if (txt.text.length==0) {
                [self showAlertWithContent:@"请输入催办留言"];
                return;
            }
            NSString* token=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
            int setid=[[[NSUserDefaults standardUserDefaults] objectForKey:@"setid"] intValue];
            
            OADocUrgeRequest* request = [[OADocUrgeRequest alloc] init];
            request.token = token;
            request.docid = [[mydict objectForKey:@"docid"] intValue];
            request.urgemsg=txt.text;
            id<ILJClient> clinet = [[OAIpdataBase shareInstance] getPool:setid];
            [clinet Doexecute:request
                     RspClass:[OADocUrgeResponse class]
                       andMsg:@"获取信息..."
                      andView:self.view
        globalTimelinePostsWithBlock:^(id rsp) {
     OADocUrgeResponse* rslt = rsp;
     
     if (rslt.ErrMsg) {
         //只有发起人才能执行催办功能
         [self showAlertWithContent:rslt.ErrMsg];
         NSLog(@"%@",rslt.ErrMsg);
     }
     else{
         
     }
 }];
        }
            break;
            
        default:
            break;
    }
    
    [txt resignFirstResponder];
    [self showMenuWithBool:FALSE complete:^()
     {
     }];
}
- (void)backToMain:(id)sender {
    UITextField* txt=(UITextField*)[self.view viewWithTag:777];
    [txt resignFirstResponder];
    [self showMenuWithBool:FALSE complete:^()
     {
     }];
}
#pragma mark createtopview
- (void)createTopView {
    if (topView) {
        [topView removeFromSuperview];
    }
    float fheight=18.0f;
    
    topView=[[UIView alloc] initWithFrame:CGRectMake(5, 10, SCREEN_WIDTH-10.0, fheight*6)];
    topView.backgroundColor=[UIColor whiteColor];
    topView.layer.cornerRadius=3.0;
    [scrollView addSubview:topView];
    
    
    int dtype=[[mydict objectForKey:@"dtype"] intValue];
    NSString* temp = [NSString stringWithFormat:@"公文编号：%@[%@]",[mydict objectForKey:@"doccode"],(dtype==0)?@"审批公文":@"文件关联"];
    float bottom=[self createLabel:temp withRect:CGRectMake(5.0, 0.0, topView.width-10.0, fheight) withfont:12.0 withalign:NSTextAlignmentLeft withview:topView withtag:0];
    
    temp=[NSString stringWithFormat:@"公文标题：%@",[mydict objectForKey:@"doctitle"]];
    bottom=[self createLabel:temp withRect:CGRectMake(5.0, bottom, topView.width-10.0, fheight) withfont:12.0 withalign:NSTextAlignmentLeft withview:topView withtag:0];
    
    temp=[NSString stringWithFormat:@"公文内容：%@",[mydict objectForKey:@"content"]];
    bottom=[self createLabel:temp withRect:CGRectMake(5.0, bottom, topView.width-10.0, fheight) withfont:12.0 withalign:NSTextAlignmentLeft withview:topView withtag:0];
    
    temp=[NSString stringWithFormat:@"公文备注：%@",[mydict objectForKey:@"dscrp"]];
    bottom=[self createLabel:temp withRect:CGRectMake(5.0, bottom, topView.width-10.0, fheight) withfont:12.0 withalign:NSTextAlignmentLeft withview:topView withtag:0];
    
    temp=[NSString stringWithFormat:@"发起时间：%@",[[mydict objectForKey:@"opdt"] substringToIndex:16]];
    [self createLabel:temp withRect:CGRectMake(topView.width-255.0, bottom, 250.0, fheight) withfont:12.0 withalign:NSTextAlignmentRight withview:topView withtag:0];
    temp=[NSString stringWithFormat:@"权值：%@",[mydict objectForKey:@"relqty"]];
    bottom=[self createLabel:temp withRect:CGRectMake(5.0, bottom, 50.0, fheight) withfont:12.0 withalign:NSTextAlignmentLeft withview:topView withtag:0];
    
    temp=[NSString stringWithFormat:@"最后处理时间：%@",[[mydict objectForKey:@"lastTime"] substringToIndex:16]];
    [self createLabel:temp withRect:CGRectMake(topView.width-255.0, bottom, 250.0, fheight) withfont:12.0 withalign:NSTextAlignmentRight withview:topView withtag:0];
    temp=[NSString stringWithFormat:@"最后处理人：%@",[mydict objectForKey:@"fnsemp"]];
    bottom=[self createLabel:temp withRect:CGRectMake(5.0, bottom, 150.0, fheight) withfont:12.0 withalign:NSTextAlignmentLeft withview:topView withtag:0];
    
}
- (float)createLabel:(NSString *)title withRect:(CGRect)rect withfont:(float)font withalign:(NSTextAlignment)alignment withview:(UIView*)view withtag:(int)tag{
    UILabel *lab1=[[UILabel alloc]initWithFrame:rect];
    lab1.backgroundColor=[UIColor clearColor];
    lab1.text=title;
    lab1.textAlignment=alignment;
    lab1.font=[UIFont systemFontOfSize:font];
    lab1.textColor=[UIColor darkTextColor];
  
    [view addSubview:lab1];
    return lab1.bottom;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)getDocHtml {
    NSString* token=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    int setid=[[[NSUserDefaults standardUserDefaults] objectForKey:@"setid"] intValue];
    
    GetOADocHTMLRequest* request = [[GetOADocHTMLRequest alloc] init];
    request.token = token;
    request.docID = [[mydict objectForKey:@"docid"] intValue];
    id<ILJClient> clinet = [[OAIpdataBase shareInstance] getPool:setid];
    [clinet Doexecute:request
             RspClass:[GetOADocHTMLResponse class]
               andMsg:@"获取信息..."
              andView:self.view
globalTimelinePostsWithBlock:^(id rsp) {
    GetOADocHTMLResponse* rslt = rsp;
    
    if (rslt.ErrMsg) {
        NSLog(@"%@",rslt.ErrMsg);
    }
    else{
        //NSLog(@"annex=%@",rslt.annexes);
//        NSLog(@"step=%@",rslt.steps);
       // NSLog(@"html=%@",rslt.HTML);
//        NSLog(@"sort=%i",rslt.flowSort);
//        NSLog(@"sort=%i",rslt.flowType);
        
        arrSteps=rslt.steps;
        arrAnnex=rslt.annexes;
        
        _tableView.frame=CGRectMake(5.0, topView.bottom+10.0, SCREEN_WIDTH-10, 44.0*(arrSteps.count+1));
        [_tableView reloadData];
        
        self.photoView = [[MessagePhotoViewDocShow alloc]initWithFrame:CGRectMake(5.0f, _tableView.bottom+10.0,SCREEN_WIDTH-10.0, 60.0f)];
        [scrollView addSubview:self.photoView];
        self.photoView.backgroundColor=[UIColor whiteColor];
        self.photoView.layer.cornerRadius=5.0;
        self.photoView.delegate = self;
        
        //添加已经存在的图片
        for (int i=0; i<[arrAnnex count]; i++) {
            NSDictionary* dict=[arrAnnex objectAtIndex:i];
            NSString* strFileName=[dict objectForKey:@"fileName"];
            NSString* strExt=[strFileName pathExtension];
            if ([strExt isEqualToString:@"png"] || [strExt isEqualToString:@"jpg"] || [strExt isEqualToString:@"bmp"]) {
                
            } else {
            //NSString* strFilePath=[dict objectForKey:@"filePath"];
                UIImage *img=[UIImage imageNamed:@"ic_text"];
                [self.photoView reloadDataWithImage:img];
            }
        }
        
        NSString* strHtml=rslt.HTML;
        if (strHtml.length>0) {
            UIWebView* _protWebView=[[UIWebView alloc]initWithFrame:CGRectMake(5.0, self.photoView.bottom+10.0, SCREEN_WIDTH-10.0, SCREEN_HEIGHT)];
            //_protWebView.scrollView.bounces=NO;
            [_protWebView setBackgroundColor:[UIColor clearColor]];
            _protWebView.delegate=self;
            [scrollView addSubview:_protWebView];
            //_protWebView.scalesPageToFit=YES;
            //strHtml=[strHtml stringByReplacingOccurrencesOfString:@"<TABLE" withString:@"<TABLE class=\"gridtable\""];
            
            //strHtml=[strHtml stringByReplacingOccurrencesOfString:@"<TABLE" withString:@"<TABLE border=\"0\" cellspacing=\"1\" bordercolor=\"#666666\" cellpadding=\"3\""];
            [self loadContent:strHtml withWeb:_protWebView];
            
            scrollView.contentSize=CGSizeMake(SCREEN_WIDTH-10.0, _protWebView.bottom+10.0);
        }
        
    }
}];
}
-(void)loadContent:(NSString*)strcon withWeb:(UIWebView*)webView {
    NSString *path1 = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path1];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"news" ofType:@"html"];
    NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
    NSString *str = [[NSString alloc] initWithData:
                     [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
    
    int fontsize = 14;
    int lineHeight = fontsize;
    
    str = [str stringByReplacingOccurrencesOfString:@"{FONT_SIZE}" withString:[NSString stringWithFormat:@"%d",fontsize]];
    str = [str stringByReplacingOccurrencesOfString:@"{LINE_HEIGHT}" withString:[NSString stringWithFormat:@"%d",lineHeight]];
    
    NSString *contentString = strcon;
    NSRange r;
    while ((r = [contentString rangeOfString:@"style=\"[^p][^>]*\\/?[^p]\"" options:NSRegularExpressionSearch]).location != NSNotFound)
        contentString = [contentString stringByReplacingCharactersInRange:r withString:@""];
    while ((r = [contentString rangeOfString:@"width=\"[^\"]*\"" options:NSRegularExpressionSearch]).location != NSNotFound)
        contentString = [contentString stringByReplacingCharactersInRange:r withString:@""];
    while ((r = [contentString rangeOfString:@"height=\"[^\"]*\"" options:NSRegularExpressionSearch]).location != NSNotFound)
        contentString = [contentString stringByReplacingCharactersInRange:r withString:@""];
    
    str = [str stringByReplacingOccurrencesOfString:@"{title}" withString:@""];
    str = [str stringByReplacingOccurrencesOfString:@"{content}" withString:contentString];
    
    [webView loadHTMLString:str baseURL:baseURL];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [arrSteps count]+1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44.0;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"newCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        //点击之后，好像2-3秒才反应过来,有延迟
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        cell.backgroundColor=[UIColor whiteColor];
        cell.contentView.backgroundColor=[UIColor whiteColor];
        
        //float mleft=5.0;
        float ffont=12.0;
        
        UIView* vi=[[UIView alloc] initWithFrame:CGRectMake(5.0, 5.0, 20.0,34.0)];
        vi.backgroundColor=[UIColor colorWithRed:63.0/255.0 green:190.0/255.0 blue:22.0/255.0 alpha:1.0];
        vi.tag=10;
        [cell.contentView addSubview:vi];
        
        UILabel* lab2=[[UILabel alloc] initWithFrame:CGRectMake(vi.right+5.0, 5.0, 125.0, 17.0)];
        lab2.backgroundColor=[UIColor clearColor];
        lab2.tag=11;
        lab2.textColor=[UIColor darkGrayColor];
        lab2.font=[UIFont systemFontOfSize:ffont];
        [cell.contentView addSubview:lab2];
        
        UILabel* lab4=[[UILabel alloc] initWithFrame:CGRectMake(lab2.right, 5, 70.0, 17.0)];
        lab4.backgroundColor=[UIColor clearColor];
        lab4.tag=14;
        lab4.textColor=[UIColor darkGrayColor];
        lab4.font=[UIFont systemFontOfSize:ffont];
        lab4.textAlignment=NSTextAlignmentCenter;
        [cell.contentView addSubview:lab4];
        
        UILabel* lab1=[[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-70.0, 5.0, 55.0, 17.0)];
        lab1.backgroundColor=[UIColor clearColor];
        lab1.tag=12;
        lab1.textColor=[UIColor redColor];
        lab1.font=[UIFont systemFontOfSize:ffont];
        lab1.textAlignment=NSTextAlignmentRight;
        [cell.contentView addSubview:lab1];
        
        UILabel* lab3=[[UILabel alloc] initWithFrame:CGRectMake(vi.right+5.0, lab2.bottom, 260.0, 17.0)];
        lab3.backgroundColor=[UIColor clearColor];
        lab3.tag=13;
        lab3.textColor=[UIColor darkGrayColor];
        lab3.font=[UIFont systemFontOfSize:ffont];
        [cell.contentView addSubview:lab3];
    }
    
    UIView* iv=(UIView*)[cell viewWithTag:10];
    UILabel* lab1=(UILabel*)[cell viewWithTag:11];
    UILabel* lab2=(UILabel*)[cell viewWithTag:12];
    UILabel* lab13=(UILabel*)[cell viewWithTag:13];
    UILabel* lab14=(UILabel*)[cell viewWithTag:14];
    
    if (indexPath.row==0) {
        iv.backgroundColor=[UIColor colorWithRed:63.0/255.0 green:190.0/255.0 blue:22.0/255.0 alpha:1.0];
        lab1.text=[NSString stringWithFormat:@"发起人:%@",[mydict objectForKey:@"opemp"]];
        lab14.text=@"公文发起";
        lab13.text=[NSString stringWithFormat:@"于%@发起",[[mydict objectForKey:@"opdt"] substringToIndex:16]];
        //msgid=[[dict objectForKey:@"docid"] intValue];
        return cell;
    }
    NSDictionary* dict=[arrSteps objectAtIndex:indexPath.row-1];
    int iitag=[[dict objectForKey:@"ifjoin"] intValue];
    lab1.text=[NSString stringWithFormat:@"待审:%@",[dict objectForKey:@"flowempstr"]];
    
    //暂时ifjoin = 1时橙色，否则绿色
    if (iitag==1) {
        iv.backgroundColor=[UIColor colorWithRed:251.0/255.0 green:183.0/255.0 blue:47.0/255.0 alpha:1.0];
    } else {
        iv.backgroundColor=[UIColor colorWithRed:63.0/255.0 green:190.0/255.0 blue:22.0/255.0 alpha:1.0];
    }
    lab14.text=[dict objectForKey:@"flowstepname"];
    if (indexPath.row==1) {
        lab2.text=@"已超时";
        lab13.text=@"正在进行";
        lab1.textColor=[UIColor colorWithRed:52.0/255.0 green:139.0/255.0 blue:197.0/255.0 alpha:1.0];
        lab13.textColor=[UIColor colorWithRed:52.0/255.0 green:139.0/255.0 blue:197.0/255.0 alpha:1.0];
        lab14.textColor=[UIColor colorWithRed:52.0/255.0 green:139.0/255.0 blue:197.0/255.0 alpha:1.0];
    }

    return cell;
}
#pragma mark MessagePhotoView
//实现代理方法
-(void)addPicker:(UIImagePickerController *)picker{
    [self presentViewController:picker animated:YES completion:nil];
}
-(void)selectItemArray:(NSMutableArray *)array {
//    for (int i=0; i<[array count]; i++) {
//        ALAsset *asset=array[i];
//        CGImageRef ref = [[asset defaultRepresentation]fullScreenImage];
//        //CGImageRef ref = [[asset defaultRepresentation]fullResolutionImage];
//        UIImage *img = [[UIImage alloc]initWithCGImage:ref];
//        
//        NSString* strTime=[Util GetCurrentTimeString];
//        NSString* strfile=[NSString stringWithFormat:@"%@.JPG",strTime];
//        NSString* strfile1=[kImagesFolder stringByAppendingPathComponent:strfile];
//        [UIImageJPEGRepresentation(img, 0.5) writeToFile:strfile1 atomically:YES];
//        
//        [_imgArr addObject:strTime];
//    }
//    [self.navigationController popViewControllerAnimated:NO];
}
- (void)takePhoto:(UIImage *)image {
//    NSString* strTime=[Util GetCurrentTimeString];
//    NSString* strfile=[NSString stringWithFormat:@"%@.JPG",strTime];
//    NSString* strfile1=[kImagesFolder stringByAppendingPathComponent:strfile];
//    [UIImageJPEGRepresentation(image, 0.5) writeToFile:strfile1 atomically:YES];
//    
//    [_imgArr addObject:strTime];
}
-(void)addUIImagePicker:(UIImagePickerController *)picker {
    //    if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
    //        self.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    //    }
    [self presentViewController:picker animated:YES completion:nil];
}
-(void)deleteImage:(NSInteger)index {
    //    NSString* picName=[AccessDB getImageInfoShow:self.EquId];
    //    NSArray* picArr=[picName componentsSeparatedByString:@"="];
    //    if (index<=[picArr count]) {
    //        [AccessDB imageDel:[self.EquId intValue] withName:[picArr objectAtIndex:1]];
    //    }
}
- (void)selectFileFromFoler {
    OASelectFileViewController* vc=[[OASelectFileViewController alloc] init];
    //[self.navigationController pushViewController:vc animated:NO];
    [self presentViewController:vc animated:NO completion:nil];
}
@end
